home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3p / usinit.z / usinit
Encoding:
Text File  |  2002-10-03  |  21.8 KB  |  331 lines

  1.  
  2.  
  3.  
  4. UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))                                                          UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _uuuu_ssss_iiii_nnnn_iiii_tttt, _uuuu_ssss_dddd_eeee_tttt_aaaa_cccc_hhhh, _uuuu_ssss_aaaa_dddd_dddd, ______uuuu_tttt_rrrr_aaaa_cccc_eeee, ______uuuu_eeee_rrrr_rrrr_oooo_rrrr - shared arena initialization
  10.  
  11. CCCC SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ####iiiinnnncccclllluuuuddddeeee <<<<uuuulllloooocccckkkkssss....hhhh>>>>
  13.  
  14.      _uuuu_ssss_pppp_tttt_rrrr______tttt _****_uuuu_ssss_iiii_nnnn_iiii_tttt _((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_f_i_l_e_n_a_m_e_))))_;;;;
  15.  
  16.      _iiii_nnnn_tttt _uuuu_ssss_aaaa_dddd_dddd _((((_uuuu_ssss_pppp_tttt_rrrr______tttt _****_u_))))_;;;;
  17.  
  18.      _vvvv_oooo_iiii_dddd _uuuu_ssss_dddd_eeee_tttt_aaaa_cccc_hhhh _((((_uuuu_ssss_pppp_tttt_rrrr______tttt _****_u_))))_;;;;
  19.  
  20.      _eeee_xxxx_tttt_eeee_rrrr_nnnn _iiii_nnnn_tttt ______uuuu_eeee_rrrr_rrrr_oooo_rrrr_;;;;
  21.  
  22.      _eeee_xxxx_tttt_eeee_rrrr_nnnn _iiii_nnnn_tttt ______uuuu_tttt_rrrr_aaaa_cccc_eeee_;;;;
  23.  
  24. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  25.      _uuuu_ssss_iiii_nnnn_iiii_tttt is used to initialize a shared arena from which related or
  26.      unrelated processes may allocate and share semaphores, locks and memory.
  27.      Locks, semaphores and memory can then be allocated using the _u_s_p_t_r__t
  28.      returned by _uuuu_ssss_iiii_nnnn_iiii_tttt.  More than one call can be made to _uuuu_ssss_iiii_nnnn_iiii_tttt to create
  29.      separate _a_r_e_n_a_s of locks and semaphores.  In fact, calls to _uuuu_ssss_iiii_nnnn_iiii_tttt may be
  30.      made on behalf of a process: when _ssss_pppp_rrrr_oooo_cccc(2) is called, an arena containing
  31.      the locks and semaphores for libc is created; when _mmmm______ffff_oooo_rrrr_kkkk(3P) is called,
  32.      an arena is set up to control the spawned tasks.  _uuuu_ssss_iiii_nnnn_iiii_tttt uses a file in
  33.      the file system to name the arena.  This name can then be used by
  34.      unrelated processes to access the arena.
  35.  
  36.      _uuuu_ssss_iiii_nnnn_iiii_tttt creates a file, _ffff_iiii_llll_eeee_nnnn_aaaa_mmmm_eeee, and maps it into the caller's space via
  37.      _mmmm_mmmm_aaaa_pppp(2).  The file is mapped using the MMMMAAAAPPPP____AAAAUUUUTTTTOOOOGGGGRRRROOOOWWWW option to _mmmm_mmmm_aaaa_pppp(2)
  38.      (see _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg(3P) for ways to alter this behavior).  By default the file
  39.      is not removed when the last process using it is finished.  This behavior
  40.      can be modified somewhat via _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg(3P).  File locks (see _ffff_cccc_nnnn_tttt_llll(2)) are
  41.      used to prevent conflicting accesses to this area during the _uuuu_ssss_iiii_nnnn_iiii_tttt call.
  42.      There is no way to tell the id of the process that actually created the
  43.      arena.  The file name given to _uuuu_ssss_iiii_nnnn_iiii_tttt may be an NFS mounted file, however
  44.      it is important to understand that NFS does not guarantee write
  45.      synchronization across multiple machines - thus if all users of an arena
  46.      are running on a single machine and using an NFS mounted file as the
  47.      arena, then all will work fine. If multiple users running on different
  48.      machines all access the same arena file, the arena will be corrupted.
  49.  
  50.      Gaining access to a particular arena for the purpose of sharing locks,
  51.      semaphores, and memory is dependent on how the processes are related and
  52.      how the arena was initialized.  If the arena was initialized (which is
  53.      the default) without the UUUUSSSS____SSSSHHHHAAAARRRREEEEDDDDOOOONNNNLLLLYYYY option to _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg(3P) then any
  54.      process with the appropriate permissions can join the arena at any time
  55.      by calling _uuuu_ssss_iiii_nnnn_iiii_tttt with _f_i_l_e_n_a_m_e.  These processes may be unrelated,
  56.      related via _ffff_oooo_rrrr_kkkk, related via _ssss_pppp_rrrr_oooo_cccc sharing file descriptors, or related
  57.      via _ssss_pppp_rrrr_oooo_cccc not sharing file descriptors.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))                                                          UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))
  71.  
  72.  
  73.  
  74.      If the arena was initialized with the UUUUSSSS____SSSSHHHHAAAARRRREEEEDDDDOOOONNNNLLLLYYYY option to
  75.      _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg(3P) then the file specified by _f_i_l_e_n_a_m_e is unlinked.  This means
  76.      that the only processes that can join the arena must somehow already have
  77.      a handle for that arena (i.e. the arena must already be mapped into their
  78.      address space).  Unrelated processes, processes spawned via _ffff_oooo_rrrr_kkkk before
  79.      the arena was initialized, and process spawned via _ssss_pppp_rrrr_oooo_cccc and not sharing
  80.      file descriptors, can never get the appropriate handle.  If a process
  81.      with the above characteristics calls _uuuu_ssss_iiii_nnnn_iiii_tttt with _f_i_l_e_n_a_m_e a NEW arena
  82.      will be created that has no relation to any other process's arena.
  83.      Processes that have the correct handle are automatically made 'members'
  84.      of the arena the first time they use a lock or semaphore.  They may
  85.      choose to call _uuuu_ssss_aaaa_dddd_dddd explicitly so that any potential errors are detected
  86.      at initialization time, rather than the first time a lock or semaphore is
  87.      used.  Previous versions of this manual page suggested calling _uuuu_ssss_iiii_nnnn_iiii_tttt
  88.      rather than _uuuu_ssss_aaaa_dddd_dddd.  This still works for any arena except one using
  89.      _////_dddd_eeee_vvvv_////_zzzz_eeee_rrrr_oooo.  _uuuu_ssss_aaaa_dddd_dddd will work for any arena.
  90.  
  91.      Certain attributes of the newly created arena may be set prior to the
  92.      call to _uuuu_ssss_iiii_nnnn_iiii_tttt by _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg(3P).  These include the maximum number of
  93.      users that can simultaneously access the arena, the maximum size the
  94.      arena can grow to, the access permissions on the arena, the type of
  95.      debugging enabled, and where in the caller's address space the arena will
  96.      be attached.  The overall size will limit how many locks and semaphores
  97.      may be allocated and how much space in the arena is left over for the
  98.      user to allocate via _uuuu_ssss_mmmm_aaaa_llll_llll_oooo_cccc(3P).  In addition to the arena header,
  99.      basic lock, and semaphore data structures, all history, metering and
  100.      debug structures are also allocated via _uuuu_ssss_mmmm_aaaa_llll_llll_oooo_cccc(3P) from the arena.  The
  101.      default size is 64K, and the default number of users is 8.
  102.  
  103.      When called, _uuuu_ssss_iiii_nnnn_iiii_tttt attempts to determine whether the arena described by
  104.      _f_i_l_e_n_a_m_e is active (i.e. whether any other processes are currently using
  105.      it).  This determination is made by checking whether any file locks are
  106.      currently active on the file.  If so, the caller registers its file lock
  107.      and merely 'joins' the collection of processes using that arena.  If
  108.      there are no file locks, the caller re-initializes the entire arena.
  109.      Problems can result if a process that did not call _uuuu_ssss_iiii_nnnn_iiii_tttt is still
  110.      accessing the arena (namely a child of a _ssss_pppp_rrrr_oooo_cccc whose parent has died)
  111.      when a new process attempts to join.  The new process will find no file
  112.      locks and re-initialize the arena, thus destroying any state the first
  113.      process had.  This problem can be solved by having all processes register
  114.      with the arena by calling _uuuu_ssss_aaaa_dddd_dddd.  Previous versions of this manual page
  115.      suggested calling _uuuu_ssss_iiii_nnnn_iiii_tttt rather than _uuuu_ssss_aaaa_dddd_dddd.  This still works for any
  116.      arena except one using _////_dddd_eeee_vvvv_////_zzzz_eeee_rrrr_oooo.  _uuuu_ssss_aaaa_dddd_dddd will work for any arena.
  117.  
  118.      As a special case, _////_dddd_eeee_vvvv_////_zzzz_eeee_rrrr_oooo can be passed as the value for _f_i_l_e_n_a_m_e.
  119.      Since _////_dddd_eeee_vvvv_////_zzzz_eeee_rrrr_oooo by definition is private to the process that opens it,
  120.      this is useful only for share group members that are sharing file
  121.      descriptors.  The space for _////_dddd_eeee_vvvv_////_zzzz_eeee_rrrr_oooo comes from the logical swap pool
  122.      (see _ssss_wwww_aaaa_pppp(1M)) rather than from the file system.  Depending on the system
  123.      configuration there may be more space in the logical swap pool than on a
  124.      file system.  The logical swap pool is also a limited resource and _uuuu_ssss_iiii_nnnn_iiii_tttt
  125.      may fail due to lack of logical swap.  It is possible to delay allocation
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))                                                          UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))
  137.  
  138.  
  139.  
  140.      of logical swap (much like the _MMMM_AAAA_PPPP______AAAA_UUUU_TTTT_OOOO_GGGG_RRRR_OOOO_WWWW option delays growth of
  141.      files) by using the _CCCC_OOOO_NNNN_FFFF______AAAA_UUUU_TTTT_OOOO_RRRR_EEEE_SSSS_VVVV option of _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg(3P).
  142.  
  143.      _uuuu_ssss_iiii_nnnn_iiii_tttt and the other lock and semaphore routines normally perform their
  144.      functions in silence.  For a verbose 'trace' of what is being done, the
  145.      global flag ____uuuuttttrrrraaaacccceeee may be set to non-zero.  In addition, if the
  146.      environment variable UUUUSSSSTTTTRRRRAAAACCCCEEEE is set, _uuuu_ssss_iiii_nnnn_iiii_tttt will automatically set
  147.      ____uuuuttttrrrraaaacccceeee.  The tracing information consists of two types of messages -
  148.      trace and error.  Error type messages can be enabled independently from
  149.      tracing messages by setting the global flag ____uuuueeeerrrrrrrroooorrrr.  In addition, if the
  150.      environment variable UUUUSSSSEEEERRRRRRRROOOORRRR is set, _uuuu_ssss_iiii_nnnn_iiii_tttt will automatically set
  151.      ____uuuueeeerrrrrrrroooorrrr.  All messages are printed on _ssss_tttt_dddd_eeee_rrrr_rrrr.  This may aid in debugging
  152.      the various error returns.
  153.  
  154.      An arena, once established, must reside at the same virtual address in
  155.      each process that attaches to it.  This implies that if more than one
  156.      process is creating an arena, the creating processes must impose the
  157.      appropriate ordering.  The following scenario will lead to such an
  158.      ordering problem:  process A creates arena A_arena, and process B creates
  159.      arena B_arena.  Then process A attempts to attach (via _uuuu_ssss_iiii_nnnn_iiii_tttt) to
  160.      B_arena.  _uuuu_ssss_iiii_nnnn_iiii_tttt will most probably fail in this case since the virtual
  161.      address for both arenas will probably be identical.  One way around this
  162.      ordering problem is to use _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg(3P) to manually set the address where
  163.      the arena should be attached.  It is then only important that all arena
  164.      creating processes agree on the addresses for each of the arenas.
  165.      Another easy way around this problem is to have all arenas created by one
  166.      process.
  167.  
  168.      A process may detach an arena by calling _uuuu_ssss_dddd_eeee_tttt_aaaa_cccc_hhhh.  This call will unmap
  169.      and close all the relevant file descriptors.  It does not check for any
  170.      outstanding locks, allocated memory, etc.  _uuuu_ssss_dddd_eeee_tttt_aaaa_cccc_hhhh will not close any
  171.      pollable semaphores, this must be done before calling _uuuu_ssss_dddd_eeee_tttt_aaaa_cccc_hhhh.  For
  172.      _ssss_pppp_rrrr_oooo_cccc processes sharing file descriptors, if one member calls _uuuu_ssss_dddd_eeee_tttt_aaaa_cccc_hhhh
  173.      then the arena is detached for the entire share group.  There is no
  174.      protection for multiple members of a share group simultaneously calling
  175.      _uuuu_ssss_dddd_eeee_tttt_aaaa_cccc_hhhh, this should not be done.
  176.  
  177.      If _uuuu_ssss_iiii_nnnn_iiii_tttt fails, it is a good idea to set the tracing variable ____uuuuttttrrrraaaacccceeee to
  178.      1 or set the environment variable UUUUSSSSTTTTRRRRAAAACCCCEEEE).  This will provide more
  179.      descriptive error messages.
  180.  
  181.      _uuuu_ssss_iiii_nnnn_iiii_tttt or _uuuu_ssss_aaaa_dddd_dddd  will fail if one or more of the following are true:
  182.  
  183.      _EEEE_AAAA_CCCC_CCCC_EEEE_SSSS    The _f_i_l_e_n_a_m_e argument could not be opened or created for
  184.                read/write.
  185.  
  186.      _EEEE_NNNN_OOOO_SSSS_PPPP_CCCC    The file specified by _f_i_l_e_n_a_m_e could not be grown to the
  187.                specified size.
  188.  
  189.      _EEEE_NNNN_OOOO_MMMM_EEEE_MMMM    There is not enough space in the arena to allocate the initial
  190.                set of required locks and semaphores.  The size of the arena
  191.                may be manipulated with _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg(3P).
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))                                                          UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))
  203.  
  204.  
  205.  
  206.      _EEEE_BBBB_UUUU_SSSS_YYYY     The caller already has mapped virtual space at the address
  207.                requested with the _CCCC_OOOO_NNNN_FFFF______AAAA_TTTT_TTTT_AAAA_CCCC_HHHH_AAAA_DDDD_DDDD_RRRR option of _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg.
  208.  
  209.      _EEEE_BBBB_UUUU_SSSS_YYYY     The caller already has mapped virtual space at the address
  210.                required by the arena when attempting to join the arena.
  211.  
  212.      _EEEE_NNNN_XXXX_IIII_OOOO     One or both of the two semaphore device files, ////ddddeeeevvvv////uuuusssseeeemmmmaaaa and
  213.                ////ddddeeeevvvv////uuuusssseeeemmmmaaaacccclllloooonnnneeee, do not exist, or the device is not configured
  214.                into the system.
  215.  
  216.      _EEEE_IIII_NNNN_VVVV_AAAA_LLLL    This error is returned if the version the currently attaching
  217.                process was compiled with is incompatible with the version
  218.                compiled into the creator of the arena.
  219.  
  220.      _EEEE_NNNN_OOOO_LLLL_CCCC_KKKK    There are no more file locks available because the system
  221.                maximum {_FFFF_LLLL_OOOO_CCCC_KKKK______MMMM_AAAA_XXXX} [see _iiii_nnnn_tttt_rrrr_oooo(2)], has been exceeded.
  222.  
  223.      _EEEE_NNNN_OOOO_LLLL_CCCC_KKKK    _f_i_l_e_n_a_m_e is in an NFS-mounted directory, and either the NFS
  224.                lock daemon, _llll_oooo_cccc_kkkk_dddd(1M) is not running (either on the server or
  225.                client) or the maximum number of file locks that _llll_oooo_cccc_kkkk_dddd can
  226.                handle has been exceeded.
  227.  
  228.      _EEEE_AAAA_GGGG_AAAA_IIII_NNNN    _f_i_l_e_n_a_m_e was set to _////_dddd_eeee_vvvv_////_zzzz_eeee_rrrr_oooo and there isn't enough logical
  229.                swap space to map the requested size arena.
  230.  
  231.      Errors may also be the result of a _mmmm_mmmm_aaaa_pppp(2) or a _ffff_cccc_nnnn_tttt_llll(2) system call.
  232.  
  233. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  234.      _ffff_cccc_nnnn_tttt_llll(2), _mmmm_mmmm_aaaa_pppp(2), _ssss_pppp_rrrr_oooo_cccc(2), _aaaa_cccc_qqqq_uuuu_iiii_rrrr_eeee______llll_oooo_cccc_kkkk(3), _bbbb_aaaa_rrrr_rrrr_iiii_eeee_rrrr(3P), _oooo_ssss_eeee_rrrr_rrrr_oooo_rrrr(3C),
  235.      _uuuu_ssss_cccc_aaaa_ssss_iiii_nnnn_ffff_oooo(3P), _uuuu_ssss_cccc_oooo_nnnn_ffff_iiii_gggg(3P), _uuuu_ssss_gggg_eeee_tttt_iiii_nnnn_ffff_oooo(3P), _uuuu_ssss_mmmm_aaaa_llll_llll_oooo_cccc(3P), _uuuu_ssss_nnnn_eeee_wwww_llll_oooo_cccc_kkkk(3P),
  236.      _uuuu_ssss_nnnn_eeee_wwww_ssss_eeee_mmmm_aaaa(3P).
  237.  
  238. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  239.      Upon successful completion, _uuuu_ssss_iiii_nnnn_iiii_tttt returns a pointer to a _u_s_p_t_r__t
  240.      structure. Otherwise, a value of NULL is returned and _eeee_rrrr_rrrr_nnnn_oooo is set to
  241.      indicate the error.
  242.  
  243.      Upon successful completion, _uuuu_ssss_aaaa_dddd_dddd returns zero.  Otherwise a value of
  244.      negative one is returned and _eeee_rrrr_rrrr_nnnn_oooo is set to indicate the error.
  245.  
  246. BBBBUUUUGGGGSSSS
  247.      _uuuu_ssss_iiii_nnnn_iiii_tttt string compares _f_i_l_e_n_a_m_e with the names of existing arenas in the
  248.      calling process.  If it finds a match, it assumes that the arena already
  249.      exists and that the caller has already (due to already having called
  250.      _uuuu_ssss_iiii_nnnn_iiii_tttt with the same _f_i_l_e_n_a_m_e or due to being related to the process that
  251.      created the arena) mapped in the arena.  This can cause unexpected
  252.      results if the application has code along the following lines:
  253.  
  254.             filename = strdup(template);
  255.             mktemp(filename);
  256.             arena = usinit(filename);
  257.             (fork, exec, communicate file name to other process,
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))                                                          UUUUSSSSIIIINNNNIIIITTTT((((3333PPPP))))
  269.  
  270.  
  271.  
  272.             it attaches to arena)
  273.             unlink(filename);
  274.  
  275.      The second time this is done, _mmmm_kkkk_tttt_eeee_mmmm_pppp could come up with the exact same
  276.      name file as before (since the first one was unlinked).  When _uuuu_ssss_iiii_nnnn_iiii_tttt
  277.      compares the name to the names of already existing and mapped arenas, it
  278.      will find a match and NOT create a new arena.  Certainly, in this case,
  279.      not the desired result.
  280.  
  281. WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS
  282.      Currently, it is not possible to create a shared arena that can be used
  283.      by programs of differing ABIs. This means that o32, N32, and N64 programs
  284.      cannot share an arena.  For primitives that can be shared between 32-bit
  285.      and 64-bit processes see _aaaa_bbbb_iiii_llll_oooo_cccc_kkkk(3P) and _tttt_eeee_ssss_tttt______aaaa_nnnn_dddd______ssss_eeee_tttt(3P).
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.